import sys, wx
import libs.dae.debug

class MainFrame(wx.Frame):
	"""
	MainFrame
	"""
	def __init__(self, parent, title):
		wx.Frame.__init__(self, parent, -1, title = title, pos = (150, 150), size = (600, 600))
		
		self.Center()
		
		# Create the menubar
		menuBar = wx.MenuBar()
		
		# and a menu 
		menu = wx.Menu()
		
		# add an item to the menu, using \tKeyName automatically
		# creates an accelerator, the third param is some help text
		# that will show up in the statusbar
		menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample")
		
		# bind the menu event to an event handler
		self.Bind(wx.EVT_MENU, self.OnClose, id=wx.ID_EXIT)
		
		# and put the menu on the menubar
		menuBar.Append(menu, "&File")
		self.SetMenuBar(menuBar)
		
		self.CreateStatusBar()
		
		
		# Now create the Panel to put the other controls on.
		self.panel = wx.Panel(self)
		self.panel.SetBackgroundColour("White") # make the background of the window
		
		# and a few controls
		"""
		text = wx.StaticText(self.panel, -1, "Hello World!")
		text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
		text.SetSize(text.GetBestSize())
		"""
		
		btn = wx.Button(self.panel, -1, "Close")
		funbtn = wx.Button(self.panel, -1, "Test")
		
		# bind the button events to handlers
		self.Bind(wx.EVT_BUTTON, self.OnClose, btn)
		self.Bind(wx.EVT_BUTTON, self.OnFunButton, funbtn)

		#splitter = wx.SplitterWindow(self, -1, style=wx.NO_3D|wx.SP_3D)
		#log = self.MakeLogWindow(splitter)
		
		#self.SetupSplitter(splitter, panel, log)
		
		
		self.MakeLogWindow()
		
		# Use a sizer to layout the controls, stacked vertically and with
		# a 10 pixel border around each
		sizer = wx.BoxSizer(wx.VERTICAL)
		#sizer.Add(text, 0, wx.ALL, 10)
		sizer.Add(self.log, 0, wx.ALL, 10)
		sizer.Add(btn, 0, wx.ALL, 10)
		sizer.Add(funbtn, 0, wx.ALL, 10)
		
		self.panel.SetSizer(sizer)
		
		self.panel.Layout()

	def SetupSplitter(self, splitter, win, log):
		splitter.SplitHorizontally(win, log)
		splitter.SetSashPosition(360, True)
		splitter.SetMinimumPaneSize(40)

	def MakeLogWindow(self):
		self.log = wx.TextCtrl(self.panel, -1, size = (550, 250), style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
		
		wx.Log_SetActiveTarget(wx.LogTextCtrl(self.log))
	
	def OnClose(self, evt):
		debug.log <> "Thank you for using GreenVex."
		
		self.Close()
		
		sys.exit()

	def OnFunButton(self, evt):
		debug.log <> "Testing..."


class Application(wx.App):
	def OnInit(self):
		self.frame = MainFrame(parent = None, title = "GreenVex")
		self.SetTopWindow(self.frame)
		self.frame.Show()
		
		return True



